//
//  CMDBHomeNoticeViewController.swift
//  CMDB
//
//  Created by 曹桂祥 on 17/4/11.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

class CMDBHomeNoticeViewController: CMDBBaseViewController {

    var tableView    : CMDBHomeNoticeTableView!
    
    private let KTitleViewH : CGFloat = 44
    
    override func setup() {
        super.setup()
        
        buildTableView()
    }
    
    func buildTableView(){
        
        let contentH     = CMDB_Screen_Height - KStatusBarHeight - KNavBarHeight - KTitleViewH - KTabBarHeight
        
        view.addSubview(UIView.CreateLine(CGRect(x: 0, y: 0, width: CMDB_Screen_Width, height: 10), lineColor: UIColor.Hex6(0x000000, alpha: 0.12)))
        
        let contentFrame = CGRect(x: 0, y: 10, width: CMDB_Screen_Width, height: contentH)
        
        tableView                              = CMDBHomeNoticeTableView(frame: contentFrame)
        tableView.separatorStyle               = .None
        tableView.showsVerticalScrollIndicator = false
        tableView.mDelegate                    = self
        tableView.controller                   = self
        tableView.backgroundColor              = UIColor.Hex6(0x000000, alpha: 0.12)
        
        view.addSubview(tableView)
    }
}

extension CMDBHomeNoticeViewController{
    
    func onHeaderRefresh() {
        
        let noticeListParam = CMDBPublicNoticeParam()
        
        noticeListParam.otype = 0
        
        noticeListParam.ptime = "0"
        
        do{
            
            try CMDBPublicNoticeManager.getInstance.queryHomePublicNoticeList(noticeListParam, tableView: tableView, handler: { (publicNoticeList) in
                    self.tableView.updateData(publicNoticeList)
                    self.tableView.updateCellAdpaters(publicNoticeList!, isInsert: false)
                }, error: { (rescode) in
                    
                }, failure: {
                    
            })
            
        }catch{
            
            
            
        }
        
//        do{
//            try CMDBDynamicManager.getInstance.queryHomeDynamicList(dynameicListParam, tableView: tableView, handler: { (homeDynamic) in
//                
//                self.tableView.updateData(homeDynamic.trends)
//                
//                self.tableView.updateCellAdpaters(homeDynamic.trends!, isInsert: false)
//                
//                }, error: { (rescode) in
//                    
//                }, failure: {
//                    
//            })
//        } catch {
//            
//        }
    }
}
